<?php

  abstract class BaseCore
  {
      //Config is statisch
      static $config = array();
      static $tpl;
      static $helper;
      static $user;
      
      protected $admin;
      private $tpl_config;
      
       /**
       * Class constructor, Instellen van basis instellingen
       * @param array $conf is de array van de config file
       * @param boolean $admin is het admin of gewoone pagina
       */
       function __construct($conf,$admin=false)
       {
             //Alles uit Config bestand in class zetten
             self::$config = $conf;
             
             //Zitten we in admin te werken
             $this->admin = $admin;

             //Smarty openen
             self::$tpl = new Smarty;
            
             //Propel starten 
             Propel::init(ROOT_PATH."kernel/config/database-conf.php");  
             set_include_path(ROOT_PATH. "kernel/libs" . PATH_SEPARATOR . get_include_path());
              
             //User starten
             self::$user = new UserLogin();
                            
             $this->setConfig();
             self::$helper = new TemplateHelpers();
             $this->openIncludes();
             $this->openLang();
             
       }
       
        /**
       * Hier worden de configs waarden door gegeven aan smarty 
       */       
       function setConfig()
       {

             $this->tpl_config[ 'dir' ]  = Realpath( ROOT_PATH . self::$config[ 'tpl_dir' ] . '/' . self::$config[ 'tpl_standard' ] .'/');
             $this->tpl_config[ 'url' ]  = self::$config['root'] . self::$config[ 'tpl_dir' ] . '/' . self::$config[ 'tpl_standard' ] .'/';

             // TPL instellingen
             self::$tpl->template_dir = ROOT_PATH . self::$config[ 'tpl_dir' ] . '/' . self::$config[ 'tpl_standard' ];
             self::$tpl->compile_dir    = ROOT_PATH . self::$config['compile_dir'];       
             self::$tpl->allow_php_tag = true;
             self::$tpl->allow_php_templates = true;
             self::$tpl->debugging = self::$config['debug'];  
             date_default_timezone_set('Europe/Amsterdam');
       }
       
       /**
       * Dit zijn de standaard template variabelen die beschikbaar moeten zijn
       */
       function globalAssigns()
       {
             self::$tpl->assign( 'tplInfo', $this->tpl_config );             
             self::$tpl->assign( 'helper', self::$helper); 
             self::$tpl->assign( 'config', self::$config);        
             self::$tpl->assign( 'user', self::$user);        
             self::$tpl->assign( 'location', isset($_GET['module'])? $_GET['module'] : 'home' );
             if($this->admin) self::$tpl->assign('modules', AdminModulePeer::getAllModules());

       }
       
       function openIncludes()
       {
           if(!$this->admin) 
           {             
                if (isset($_GET['module']))
                {
                    if(file_exists( ROOT_PATH. 'modules/' . $_GET['module'] . '/' . $_GET['module'].'Action.php'))
                    {
                        include ROOT_PATH. 'modules/' . $_GET['module'] . '/' . $_GET['module'].'Action.php';    
                    }
                    else
                    {
                        self::$tpl->display('404.tpl'); die;
                    }  
                }
           }
           else
           {
              if (isset($_GET['module']))
                {
                    if(file_exists( ROOT_PATH. 'admin/modules/' . $_GET['module'] . '/' . $_GET['module'].'Action.php'))
                    {
                        include ROOT_PATH. 'admin/modules/' . $_GET['module'] . '/' . $_GET['module'].'Action.php';    
                    }
                    else
                    {
                        self::$tpl->display('404.tpl'); die;
                    }  
                }
               
           }
       } 
       
       function openLang()
       {
            include ROOT_PATH .'lang/' . core::$config['language'].'.inc';
       }
      
  }
?>
